
$('.numeroDecimal').on('keydown keypress keyup paste input', function () {   
    while ( ($(this).val().split(".").length - 1) > 1 ) {
        $(this).val($(this).val().slice(0, -1));
        if ( ($(this).val().split(".").length - 1) > 1 ) {
            continue;
        } else {
            return false;
        }
    }

    // replace any character that's not a digit or a dot
    $(this).val($(this).val().replace(/[^0-9.]/g, ''));

    // now cut the string with the allowed number for the integer and float parts
    // integer part controlled with the int_num_allow variable
    // float (or decimal) part controlled with the float_num_allow variable
    var int_num_allow = 12;
    var float_num_allow = 2;

    var iof = $(this).val().indexOf(".");

    if ( iof !== -1 ) {
        // this case is a mouse paste (probably also other events) with more numbers before the dot than is allowed
        // the number can't be "sanitized" because we can't "cut" the integer part, so we just empty the element and optionally change the placeholder attribute to something meaningful
        if ( $(this).val().substring(0, iof).length > int_num_allow ) {
            $(this).val('');
        }
        // cut the decimal part
        $(this).val($(this).val().substring(0, iof + float_num_allow + 1));
    } else {
        $(this).val($(this).val().substring(0, int_num_allow));
    }
    return true;

});


$('.numeroEntero').on('keydown keypress keyup paste input', function () {   
    while ( ($(this).val().split(".").length - 1) > 1 ) {
        $(this).val($(this).val().slice(0, -1));
        if ( ($(this).val().split(".").length - 1) > 1 ) {
            continue;
        } else {
            return false;
        }
    }

    $(this).val($(this).val().replace(/[^0-9]/g, ''));

    var int_num_allow = 12;
    var float_num_allow = 0;

    var iof = $(this).val().indexOf(".");

    if ( iof !== -1 ) {
        if ( $(this).val().substring(0, iof).length > int_num_allow ) {
            $(this).val('');
        }
        $(this).val($(this).val().substring(0, iof + float_num_allow + 1));
    } else {
        $(this).val($(this).val().substring(0, int_num_allow));
    }
    return true;
});



//UTILIZADOS ANTERIORMENTE QUEDA POR SI ACASO
//
//$('.numeroDecimal2').keypress(function(event) {
//    $(this).val($(this).val().replace(/[^0-9.]/g, ''));
//    if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
//        if (event.keyCode !== 8 && event.keyCode !== 46) { //exception
//            event.preventDefault();
//        }
//    }
//    if (($(this).val().indexOf('.') != -1) && ($(this).val().substring($(this).val().indexOf('.'), $(this).val().indexOf('.').length).length > 2)) {
//        if (event.keyCode !== 8 && event.keyCode !== 46) { //exception
//            event.preventDefault();            
//        }
//    }
//
//
//
//});
//
//$('.numeroEntero2').keypress(function(event) {
//    if (event.which < 48 || event.which > 57) {
//        event.preventDefault();
//    }
//});